import { $get, $post, $postForm, $postFile, $del } from 'utils/request'
import { getAccessToken } from 'utils/headerToken'
import { BASE_URL } from 'config/constant'
const tenantId = localStorage.getItem('tenantId')
// 模版配置
export let initTemp = async (templateCode, params = {}) => {
  let url = `$ztnt/v1/${tenantId}/form-list-config/${templateCode}/filterDetail`
  let data = await $get(url,{
    tenantId,
    ...params
  })
  return data
}
// 根据formTemplateId获取模板的字段信息
export let getTempInIdfoApi = async (formTemplateId) => {
  let url = `$ztnt/v1/${tenantId}/form-template/${formTemplateId}`
  let data = await $get(url)
  return data
}
// 根据code获取模板的字段信息
export let getTempInfoApi = async (docTempCode, templateVersion) => {
  let url = `$ztnt/v1/${tenantId}/form-template/detail-code?code=${docTempCode}&templateVersion=${templateVersion || ''}&statusFlag=true`
  let data = await $get(url)
  return data
}

//  账号登录 -在登录失败10次之后，获取验证码图片接口
export let getlovoptions = async (params) => {
  let url = `$ztnt/v1/$tenantId/lov-value/info`
  let data = await $get(url, params)
  return data
}
// 根据编码获取值集视图信息
export let getlovViewCodeInfo = async (params = {}, urls, lovViewCode) => {
  let url = `$ztnt${urls}?lovViewCode=${lovViewCode}`
  let data = await $get(url, params)
  return data
}
// 值集-信息
export let getlovinfo = async (params = {}, urls, code) => {
  let url = `$ztnt${urls}?code=${code}`
  let data = await $get(url, params)
  return data
}
// 值集-信息
export let getlovList = async (urls, params = {}) => {
  let url = `${urls}`
  let data = await $get(url, params)
  return data
}
// 静态值集列表
export let lovList = async (params = {}, urls, code) => {
  let url = `$ztnt${urls}?lovCode=${code}`
  let data = await $get(url, params)
  return data
}

// 下拉分页
export let getPageSelectApi = async (url, params) => {
  let data = await $get(url, params)
  return data
}

/*
**
上传相关
*/

// 上传文件-申请目录
export let getFileBucketApi = async () => {
  let url = `$zfil/v1/$tenantId/file/bucket?access_token=${getAccessToken()}`
  let data = await $post(url)
  return data
}

// 删除文件-根据目录和文件名删除文件
export let getFileBucketDirdele = async (dir, object) => {
  let url = `$zfil/v1/${tenantId}/file/bucket/${dir}/${object}?access_token=${getAccessToken()}`
  let data = await $del(url)
  return data
}

// 上传文件-上传文件法律实体
export let getFileBucketPublicDirApiBus = async (dir, formData) => {
  // let url = `$zfil/v1/${tenantId}/file/bucket/${dir}?access_token=${getAccessToken()}`
  let url = `$zfil/v1/${tenantId}/public-file/bucket/${dir}?access_token=${getAccessToken()}`
  let data = await $postFile(url, formData)
  return data
}
// 下载文件-根据目录和文件名重定向到文件下载地址
export function getFileBucketDirobject(dir, object) {
  return `${BASE_URL}/zfil/v1/${tenantId}/file/bucket/${dir}/${object}?access_token=${getAccessToken()}`
}
// dir 获取目录内文件集合
export function getFileBucketDirlist(dir) {
  return request({
    url: `$zfil/v1/${tenantId}/file/bucket/${dir}`,
    method: 'get'
  })
}

// dir 获取目录内文件集合
export let getFileDirApi = async (dir) => {
  let url = `$zfil/v1/${tenantId}/file/bucket/${dir}`
  let data = await $get(url, {})
  return data
}
// dir 获取目录内文件集合
export let getFileguidApi = async (param) => {
  let url = `$zfil/v1/file-access/getFile`
  let data = await $post(url, param)
  return data
}
// 发送验证码
export let getSendCodeApi = async (params) => {
  let url = `$ztnt/v1/company/register/send-code`
  let data = await $get(url, params)
  return data
}
// 企信宝接口
export let getCompanySearchApi = async (params) => {
  let url = `$ztnt/v1/register/company/search`
  let data = await $get(url, params)
  return data
}
// 创建企业
export let postRegisterCompanyApi = async (params) => {
  let url = `$ztnt/v1/register/company`
  let data = await $post(url, params)
  return data
}
// 根据场景code获取信息
export let sceneDetail = async (params) => {
  let url = `$zfil/v1/${tenantId}/file-access/scene/detail-code`
  let data = await $get(url, params)
  return data
}
//企业关系详情
export let rfxbusinessrelationshipsById = async (id) => {
  let url = `/zrfx/v1/${tenantId}/rfxbusinessrelationships/${id}`
  let data = await $get(url)
  return data
}